<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <!-- <meta charset="GBK"> -->
    <!-- <meta charset="GB2312"> -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action=" " method="GET">
        <p>
            <label for="">用户名：</label><input name="user" type="text">
        </p>
        <p>
            <label for="">密&emsp;码：</label><input name="pwd" type="text">
        </p>
        <p>
            <label for="">手机号：</label><input name="phone" type="text">
        </p>
        <p>
            <label for="">邮&emsp;箱：</label><input name="email" type="text">
        </p>
        <p><input type="submit" value="提交" /></p>
    </form>
    <button id="get">获取</button>
    <!-- <button id="set">设置</button> -->
</body>
<script>
    var get = document.getElementById("get");
    var set = document.getElementById("set");
    get.onclick = function () {
        console.log(location.search);
        var str = location.search;
        
        var user = str.indexOf("user=");
        var a = str.indexOf("&");

        var pwd = str.indexOf("pwd=");
        var b = str.indexOf("&", pwd);

        var phone = str.indexOf("phone=");
        var c = str.indexOf("&", phone);

        var email = str.indexOf("email=");
        for (var k in str) {
            if (k == user) {
                var x = str.slice(user + 5, a);
                console.log(x);
            } else if (k == pwd) {
                var y = str.slice(pwd + 4, b);
                console.log(y);
            } else if (k == phone) {
                var z = str.slice(phone + 6, c);
                console.log(z);
            } else if (k == email) {
                var q = str.slice(email + 6);
                console.log(q);
            }
        }
        var obj = {
            user: x,
            pwd: y,
            phone: z,
            email: q,
        }
        console.log(obj);
    }

</script>

</html>